﻿@{
    ViewBag.Title = "Home Page";
}
<h2>@ViewBag.Message</h2>
<p>
    To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">
        http://asp.net/mvc</a>.
</p>
<div id="loading">
    ...主人，正在努力为您加载中...</div>
<div id="div-box" title="登录">
    <p>
        <label for="txtLoginUserName">
            用户名：</label>
        <input id="txtLoginUserName" type="text" />
    </p>
    <p>
        <label for="txtLoginPassword">
            密码：</label>
        <input id="txtLoginPassword" type="password" />
    </p>
</div>
@if (false)
{ 
    <script src="../../Scripts/jquery.validate-vsdoc.js" type="text/javascript"></script>
}
<script type="text/javascript">
    $(function () {
        $("#loading").ajaxStart(function () {
            $(this).fadeIn("slow");
        }).ajaxComplete(function(){
            $(this).fadeOut("slow");
        });
        $("#LoginButton").click(function () {
            $("#div-box").dialog("open");
        });
        $("#div-box").dialog({
            autoOpen: false,
            resizable: false,
            modal: true,
            buttons: {
                "确定": function () {
                    var username = $("#txtLoginUserName");
                    var userpass = $("#txtLoginPassword");
                    if (username.val() == "") {
                        alert("用户名不能为空！");
                        username.focus();
                    } else if (userpass.val() == "") {
                        alert("密码不能为空！");
                        userpass.focus();
                    } else {
                        $.ajax({
                            type: "POST",
                            url: "/User/LogIn",
                            data: { "user.UserName": username.val(),
                                "user.Password": userpass.val()
                            },
                            timeout: 20000,
                            success: function (data) {
                                if (data.Success) {
                                    $("#logindisplay").html('<text>欢迎<strong>' + username.val() + '</strong>!<a href="/User/LogOff">注销</a></text>');
                                    $("#div-box").dialog("close");
                                } else {
                                    userpass.val('');
                                    username.val('');
                                    username.focus();
                                    alert(data.Message);
                                }
                            }
                        });
                    }
                },
                "取消": function () {
                    $(this).dialog("close");
                }
            }
        });
    });
</script>
